Multiple Linear Regression for Robot Calibration

In this lab, we will illustrate the use of multiple linear regression for calibrating robot control. In addition to reviewing the concepts in the multiple linear regression demo, you will see how to use multiple linear regression for time series data -- an important concept in dynamical systems such as robotics.

The robot data for the lab is taken generously from the TU Dortmund's Multiple Link Robot Arms Project. As part of the project, they have created an excellent public dataset: MERIt -- A Multi-Elastic-Link Robot Identification Dataset that can be used for understanding robot dynamics. The data is from a three link robot:

We will focus on predicting the current draw into one of the joints as a function of the robot motion. Such models are essential in predicting the overall robot power consumption. Several other models could also be used.

Load and Visualize the Data

First, import the modules we will need.

The full MERIt dataset can be obtained from the MERIt site. But, this dataset is large. Included in this repository are two of the ten experiments. Each experiments corresonds to 80 seconds of recorded motion. We will use the following files:

If you are running this notebook on Google colab, you will need to run the following commands to load the files onto your local machine. Otherwise, if you have clone the repository, the files should be in the directory as the notebook and you can skip this step.

Below, I have supplied the column headers in the names array. Use the pd.read_csv command to load the training data in exp1.csv. Use the index_col option to specify that column 0 (the one with time) is the index column. You can review simple linear regression demo for examples of using the pd.read_csv command.

Print the first six lines of the pandas dataframe and manually check that they match the first rows of the csv file.

From the dataframe df, extract the time indices into a vector t and extract I2, the current into the second joint. Place the current in a vector y and plot y vs. t. Label the axes with the units.

Use all the samples from the experiment 1 dataset to create the training data:

Fit a Linear Model

Use the sklearn.linear_model module to create a LinearRegression class regr.

Train the model on the training data.

Using the trained model, compute, ytrain_pred, the predicted current. Plot ytrain_pred vs. time t. On the same plot, plot the actual current ytrain vs. time t. Create a legend for the plot.

Measure the normalized RSS given by `RSS / (n s^2_y).

Measure the Fit on an Indepdent Dataset

Up to now, we have only tested the model on the same data on which it was trained. In general, we need to test model on independent data not used in the training. For this purpose, load the data in exp2.csv. Compute the regression predicted values on this data and plot the predicted and actual values over time.

Measure the normalized RSS on the test data.